package o;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnKeyListener;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.agreement.api.ui.ITermsActivityProtocol;
import huawei.widget.HwButton;
import o.axa.b;
import o.axa.h;
import o.axx.d;

public class axu extends evx {
    private ImageView ʻ;
    cks ˊ;
    private HwButton ˋ;
    private Context ˎ;
    private axq ˏ;
    private HwButton ॱ;
    private axv ॱॱ = axv.ˊ();
    private final axy ᐝ;

    static class a extends axu {
        a(Activity activity) {
            super(activity, null, null);
            awg.ˎ.ˋ("ProtocolOverseaAlertDialog", "DumbProtocolOverseaAlertlDialog nothing to do.");
        }
    }

    static class c implements OnKeyListener {
        private d ˋ;

        private c(d dVar) {
            this.ˋ = dVar;
        }

        public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
            return this.ˋ.ॱ(i, keyEvent);
        }
    }

    axu(Activity activity, @Nullable ITermsActivityProtocol iTermsActivityProtocol, @Nullable axx o_axx) {
        this.ˎ = activity;
        d ˏ = ˏ();
        int viewType = iTermsActivityProtocol == null ? 0 : iTermsActivityProtocol.getViewType();
        this.ᐝ = new axy(activity, viewType);
        if (viewType == 1) {
            axq o_axr = new axr(activity);
            o_axr.setCanceledOnTouchOutside(false);
            o_axr.setOnCancelListener(new OnCancelListener(this) {
                final /* synthetic */ axu ॱ;

                {
                    this.ॱ = r1;
                }

                public void onCancel(DialogInterface dialogInterface) {
                    if (this.ॱ.ˊ != null) {
                        this.ॱ.ˊ.upgrade();
                    }
                }
            });
            o_axr.setOnKeyListener(new c(ˏ));
            this.ˏ = o_axr;
        } else {
            this.ˏ = new axl(activity, ˏ);
        }
        ˎ(this.ᐝ, viewType);
        if (o_axx != null) {
            o_axx.ˎ(ˏ);
        }
        ˊ(this.ᐝ);
    }

    private d ˏ() {
        return new d(this) {
            final /* synthetic */ axu ˏ;

            {
                this.ˏ = r1;
            }

            public boolean ॱ(int i, KeyEvent keyEvent) {
                if (i != 4) {
                    return false;
                }
                boolean ˊ = this.ˏ.ᐝ.ˊ(i, keyEvent);
                awx ʻ = axg.ˏ().ʻ();
                if (!(this.ˏ.ʻ == null || ʻ == null)) {
                    this.ˏ.ʻ.setImageResource(ʻ.ᐝ());
                    this.ˏ.ʻ.setVisibility(0);
                }
                this.ˏ.ˊ();
                return ˊ;
            }
        };
    }

    static axu ॱ(Activity activity, @Nullable ITermsActivityProtocol iTermsActivityProtocol, axx o_axx) {
        if (activity.isFinishing()) {
            return new a(activity);
        }
        return new axu(activity, iTermsActivityProtocol, o_axx);
    }

    void ˎ(cks o_cks) {
        this.ˊ = o_cks;
    }

    private void ˎ(View view, int i) {
        this.ˋ = (HwButton) view.findViewById(b.ˈ);
        this.ॱ = (HwButton) view.findViewById(b.ʾ);
        this.ˋ.setOnClickListener(this);
        this.ॱ.setOnClickListener(this);
        ˊ();
        awx ʻ = axg.ˏ().ʻ();
        ((ImageView) view.findViewById(b.ॱˎ)).setImageResource(ʻ.ˏ());
        ((TextView) view.findViewById(b.ʽॱ)).setText(ʻ.ॱॱ());
        ((TextView) view.findViewById(b.ᐝॱ)).setText(ʻ.ʼ());
        TextView textView = (TextView) view.findViewById(b.ॱˋ);
        if (i == 1) {
            textView.setText(ʻ.ˊ());
        } else {
            textView.setText(ʻ.ʽ());
        }
        this.ʻ = (ImageView) view.findViewById(b.ʼॱ);
        if (this.ॱॱ.ॱ == 1) {
            this.ʻ.setImageBitmap(null);
            this.ʻ.setVisibility(8);
            return;
        }
        this.ʻ.setImageResource(ʻ.ᐝ());
        this.ʻ.setVisibility(0);
    }

    private void ˊ() {
        if (this.ॱॱ.ॱ == 1) {
            this.ˋ.setText(h.ʻॱ);
            this.ॱ.setText(h.ॱˋ);
            return;
        }
        this.ˋ.setText(h.ॱˎ);
        this.ॱ.setText(h.ॱॱ);
    }

    private void ˋ() {
        if (this.ॱॱ.ॱ != 1) {
            this.ᐝ.ॱ();
            if (this.ʻ != null) {
                this.ʻ.setImageBitmap(null);
                this.ʻ.setVisibility(8);
            }
        } else if (this.ˊ != null) {
            this.ˊ.enableNetworking();
            ˎ();
            this.ॱॱ.ॱ();
        }
    }

    private void ॱ() {
        if (this.ॱॱ.ॱ == 1) {
            this.ᐝ.ˊ();
            awx ʻ = axg.ˏ().ʻ();
            if (this.ʻ != null && ʻ != null) {
                this.ʻ.setImageResource(ʻ.ᐝ());
                this.ʻ.setVisibility(0);
                return;
            }
            return;
        }
        ʽ();
    }

    public void ˎ() {
        if (this.ˏ != null) {
            try {
                this.ˏ.dismiss();
            } catch (IllegalArgumentException e) {
                awg.ˎ.ˎ("ProtocolOverseaAlertDialog", "dlProgressDialog dismiss IllegalArgumentException");
            }
            this.ˏ = null;
        }
    }

    private void ˊ(View view) {
        if (this.ˎ == null || ((Activity) this.ˎ).isFinishing()) {
            Object obj;
            awg o_awg = awg.ˎ;
            String str = "ProtocolOverseaAlertDialog";
            StringBuilder append = new StringBuilder().append("show dlg error, mContext = ").append(this.ˎ).append(", mContext.isFinishing is ");
            if (this.ˎ == null) {
                obj = "mContext == null";
            } else {
                obj = Boolean.valueOf(((Activity) this.ˎ).isFinishing());
            }
            o_awg.ˊ(str, append.append(obj).toString());
            return;
        }
        try {
            this.ˏ.ॱ(view);
            ayw.ˊ(this.ˏ.getWindow());
            if (this.ˋ != null) {
                this.ˋ.setAllCaps(true);
            }
            if (this.ॱ != null) {
                this.ॱ.setAllCaps(true);
            }
        } catch (Exception e) {
            awg.ˎ.ˊ("ProtocolOverseaAlertDialog", "show dlg error, e: " + e);
        }
    }

    private void ʽ() {
        ˎ();
        if (this.ˊ != null) {
            this.ˊ.upgrade();
        }
    }

    public void ˋ(View view) {
        if (view.getId() == b.ʾ) {
            awg.ˎ.ˋ("ProtocolOverseaAlertDialog", "cancel");
            ॱ();
            ˊ();
        } else if (view.getId() == b.ˈ) {
            awg.ˎ.ˋ("ProtocolOverseaAlertDialog", "confirm");
            ˋ();
            ˊ();
        }
    }
}
